def crf_model_1():
    """例11.1"""

    def t1(y0, y1, x, i):
        return int(y0 == 0 and y1 == 1 and i in {1, 2})

    def t2(y0, y1, x, i):
        return int(y0 == 0 and y1 == 0 and i in {1})

    def t3(y0, y1, x, i):
        return int(y0 == 1 and y1 == 0 and i in {2})

    def t4(y0, y1, x, i):
        return int(y0 == 1 and y1 == 0 and i in {1})

    def t5(y0, y1, x, i):
        return int(y0 == 1 and y1 == 1 and i in {2})

    def s1(y0, x, i):
        return int(y0 == 0 and i in {0})

    def s2(y0, x, i):
        return int(y0 == 1 and i in {0, 1})

    def s3(y0, x, i):
        return int(y0 == 0 and i in {1, 2})

    def s4(y0, x, i):
        return int(y0 == 1 and i in {2})

    w1 = [1, 0.6, 1, 1, 0.2]
    t = [t1, t2, t3, t4, t5]
    w2 = [1, 0.5, 0.8, 0.5]
    s = [s1, s2, s3, s4]

    return w1, t, w2, s


def crf_model_2():
    """新增例11.4"""

    def t1(y0, y1, x, i):
        return int(y0 in {0} and y1 in {1} and x in {(0, 1, 0), (0, 1, 1), (0, 0, 0), (0, 0, 1)} and i in {1, 2})

    def t2(y0, y1, x, i):
        return int(y0 in {0} and y1 in {0} and x in {(1, 1, 0), (1, 1, 1), (1, 0, 0), (1, 0, 1)} and i in {1})

    def t3(y0, y1, x, i):
        return int(y0 in {1} and y1 in {0, 1} and x in {(0, 0, 0), (1, 1, 1)} and i in {2})

    def t4(y0, y1, x, i):
        return int(y0 in {1} and y1 in {1} and x in {(0, 1, 0), (0, 1, 1), (0, 0, 0), (0, 0, 1), (1, 1, 0), (1, 1, 1),
                                                     (1, 0, 0), (1, 0, 1)} and i in {2})

    def t5(y0, y1, x, i):
        return int(y0 in {0, 1} and y1 in {0} and x in {(0, 1, 0), (0, 1, 1), (1, 1, 0), (1, 1, 1)} and i in {1, 2})

    def s1(y0, x, i):
        return int(y0 in {0} and x in {(0, 1, 1), (1, 1, 0), (1, 0, 1)} and i in {0, 1, 2})

    def s2(y0, x, i):
        return int(y0 in {1} and x in {(0, 1, 0), (0, 1, 1), (0, 0, 0), (0, 0, 1), (1, 1, 0), (1, 1, 1), (1, 0, 0),
                                       (1, 0, 1)} and i in {0})

    def s3(y0, x, i):
        return int(y0 in {0} and x in {(0, 1, 1), (1, 1, 0), (1, 0, 1)} and i in {0, 1})

    def s4(y0, x, i):
        return int(y0 in {1} and x in {(1, 0, 1), (0, 1, 0)} and i in {0, 2})

    w1 = [1, 0.6, 1.2, 0.2, 1.4]
    t = [t1, t2, t3, t4, t5]
    w2 = [1, 0.2, 0.8, 0.5]
    s = [s1, s2, s3, s4]

    return w1, t, w2, s
